﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using BLL.System;

public partial class Admin_Left : System.Web.UI.Page
{
    public string text;
    DataTable BT, ST;
    TreeServices objTreeServices = new TreeServices();
    /// <summary>
    /// 生成树
    /// </summary>
    /// <returns>返回一个字符串</returns>
    public string MenuLoad()
    {
        //填充树干的内容
        string trees = "", bs = "";
        int i = 1;
        BT = objTreeServices.SelectAllBig_Class()[0];
        ST = objTreeServices.SelectAllSmall_Class(Convert.ToInt32(Session["AID"].ToString().Trim()))[0];
        //ST = objTreeServices.SelectAllSmall_Class(Convert.ToInt32(1))[0];
        DataRow[] drs = BT.Select("");
        foreach (DataRow r in drs)
        {
            trees += "<table align='left' border=0 cellPadding=0 cellSpacing=0><tr height=2><td></td></tr></table><table width='158' border=0 align='center' cellPadding=0 cellSpacing=0  bgcolor=#c5e9f7><Tbody>";
            bs = "<font color='#003366'>" + r["ABFName"].ToString() + "</font>";
            trees += "<tr><td height=25 background='im/a.gif' id='imgmenu" + i + "' style='CURSOR: hand' onclick='showsubmenu(" + i + ")'>&nbsp;&nbsp;<SPAN>" + bs + "</SPAN></td></tr>	<tr><td id='submenu" + i + "' style='DISPLAY: none'><DIV align='left'><table width='100%' cellPadding=0 cellSpacing=3><Tbody>";
            string parentid = r["ABFID"].ToString();
            trees += CreateNode(parentid) + "</Tbody></table></DIV></td></tr></Tbody></table>";
            i++;
        }
        return trees;
    }
    /// <summary>
    /// 添加子
    /// </summary>
    /// <param name="parentid">根的ID</param>
    /// <returns></returns>
    private string CreateNode(string parentid)
    {
        //填充树枝的内容
        string Nodes = "";
        DataRow[] drsr = ST.Select("ABFID = " + parentid);
        foreach (DataRow rw in drsr)
        {
            Nodes = Nodes + "<tr><td><font color=#ff0000><IMG height=13 src='image/jt.gif' width=12>&nbsp;</font>" +
                "<A href='" + rw["ALURL"] + "' target='mainFrame'>" + rw["ALName"].ToString() + "</A></td></tr>";
        }
        return Nodes;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["admin"].ToString().Trim() != "1")
        {
            Response.Redirect("Login.aspx");
        }
    }
}
